<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('网店商品信息')"/>
    <th:block th:include="include :: list-css"/>
    <style type="text/css">
        label.layui-form-label {
            width: 95px;
            padding-right: 0px;
        }

        .layui-form-radio {
            margin-top: 0
        }

        .importTable {
            empty-cells: show;
            border-collapse: collapse;
            border-spacing: 0;
        }

        .listext th {
            background: #eee;
            color: #3366cc;
        }

        .listext th, .listext td {
            border: solid 1px #ddd;
            text-align: left;
            padding: 10px;
            font-size: 14px;
        }

        #importProgress {
            z-index: 20200202;
            background-color: #000;
            opacity: 0.3;
            display: none;
        }

        .importProgress {
            width: 300px;
            z-index: 20202222;
            position: fixed;
            top: 34%;
            left: 40%;
            display: none;
        }

        /* .layui-table-box{overflow-x: auto !important;}
        .layui-table-header{display: inline-block !important;} */
    </style>
</head>
<body>
<div class="main-content">
    <div class="content-right">
        <div class="search-top">
            <span>查询条件</span>
            <a href="javascript:;" layadmin-event="flexible" class="menuBtn">
                <i class="layui-icon layui-icon-spread-left" id="LAY_app_flexible" style="color: #fff;"></i>
            </a>
        </div>
        <div class="panel layout-expand layui-expand-east">
            <div class="panel-header">
                <div class="panel-tool" style="text-align: center; width: 26px;height: 30px;line-height: 30px;">
                    <a href="javascript:;" layadmin-event="flexible" class="menuBtn">
                        <i class="layui-icon layui-icon-shrink-right" id="LAY_app_flexible" style="color: #fff;"></i>
                    </a>
                </div>
            </div>
            <div class="panel-body panel-title" style="text-align: center; width: 26px;">查<br>询<br>条<br>件</div>
        </div>
        <form class="layui-form">
            <th:block th:include="listinclude :: searchRight('page')"/>
        </form>
    </div>
    <div class="mid-content">
        <table class="layui-hide" id="dhtable" lay-filter="ftable"></table>
    </div>
</div>
<!-- 表格头部工作栏-->
<script type="text/html" id="toolbar">
    <div class="layui-btn-container">
        <!-- <div class="layui-btn layui-table-tools sdbtn" lay-event="sdbtn" shiro:hasPermission="hr:amazonanalysis:view">
            <i class="dhicon dh-random"></i> 手动刷新
        </div> -->
        <div class="layui-btn layui-table-tools importbtn-bg" lay-event="exportbtn"
             shiro:hasPermission="hr:amazonanalysis:export">
            <i class="dhicon dh-download"></i> 导出
        </div>
    </div>
</script>

<th:block th:include="include :: footer"/>
<th:block th:include="include :: businessJS"/>
<th:block th:include="include :: searchJS"/>
<th:block th:include="listinclude :: list-templeat"/>
<script th:inline="javascript">
    /*<![CDATA[*/
    var prefix = ctx + "hr/amazonanalysis";
    var gridColumns = [[${gridColumns}]],
        importFields = [[${importFields}]],
        ali1688AppKey = [[${ali1688AppKey}]],
        ali1688EcpApiUrl = [[${ali1688EcpApiUrl}]],
        session = [[${session}]],
        moduleTable = [[${moduleTable}]];
    /*]]>*/
</script>
<script type="text/javascript">
    var sellerSku=''
    let url = window.location.href;
    if(url.indexOf('?') !== -1){
        let obj = {};
        let arr = url.slice(url.indexOf('?')+1).split('&');
        arr.forEach(item => {
            let param = item.split('=');
            obj[param[0]] = param[1];
        })
        sellerSku=obj.sellerSku;
    }
    var element, thStr;
    var fieldWidth = {},		//导入列表字段宽度
        filedRequired = {},		//导入列表必填字段
        dateFiled = [],			//导入列表日期字段
        hasNull = false;		//导入数据必填字段有空值
    $.each(gridColumns.dictionaryForPageFieldList, function (i, v) {
        fieldWidth[v.fields] = v.fieldFrontWidth
        if (v.fieldFrontRequired) filedRequired[v.fields] = v.fieldName;
        if (v.fieldFrontType == 't_date') dateFiled.push(v.fields);
    })
    var $, layer, laydate, form, table, wherestr = {};
    layui.use(['table', 'laydate', 'form', 'layer', 'jquery', 'element'], function () {
        $ = layui.$, layer = layui.layer, laydate = layui.laydate , form = layui.form, table = layui.table, element = layui.element;
        serachRender();//查询条件初始渲染集合
        changeDropdown('fSl');//导入窗口——税率下拉可编辑赋事件
        $.tablelist.init({
            elem: '#dhtable'
            , modalName: "产品信息"
            , url: prefix + '/list2?sellerSku='+sellerSku+'&order=desc'
            , totalRow: gridColumns.totalRow
            , cols: [gridColumns.gridBody]
            , toolbar: '#toolbar'
            , defaultToolbar: [{title: '列设置', layEvent: 'fieldSet', icon: 'layui-icon-set'}] //这里在右边显示
            , height: 'full-65'
            , parseData: function (res) { //res 即为原始返回的数据
                var objpage = sessionStorage.getItem(moduleTable + 'checkdata')
                if (objpage) {
                    objpage = JSON.parse(objpage)
                    res.data.map((v, i) => {
                        objpage.map((n, m) => {
                            if (v.guid == n.guid) {
                                v.LAY_CHECKED = true
                            }
                        })
                    })
                }
            }
        });

        //监听排序事件
        table.on('sort(ftable)', function (obj) {
            $.tablelist.sort('dhtable', obj);
        });


        //头工具栏事件
        table.on('toolbar(ftable)', function (obj) {
            switch (obj.event) {
                case 'exportbtn':
                    $.ajax({
                        url: '/hr/amazonanalysis/export',
                        type: 'GET',
                        data: getWherestr(),
                        dataType: 'json',
                        beforeSend: function () {
                            showloadings(true);
                        },
                        success: function (result) {
                            if (result.code == 0) {
                                window.location.href = ctx + "common/download?fileName=" + encodeURIComponent(result.msg) + "&delete=" + true;
                                parent.$('.page-loading').hide();//页面进行了跳转刷新，需要手动关闭页面的加载动画
                            } else if (result.code == web_status.WARNING) {
                                $.modal.alertWarning(result.msg)
                            } else {
                                $.modal.alertError(result.msg);
                            }
                            showloadings(false);
                        }
                    });
                    break;
                case 'sdbtn'://店铺订单 手动刷新
                    // console.log("手动 刷新")
                    var index = layer.load();
                    $.post(ali1688EcpApiUrl + '/api/amazon/getAmazonOrderInfo', {
                        userId: session.userId
                    }, function (result) {
                        if (result.success == true) {
                            setTimeout(function () {
                                table.reload('dhtable', {page: {curr: 1}, where: getWherestr()});
                            }, 1000);
                            layer.closeAll();
                        } else {
                            layer.alert(result.message, {icon: 2});
                        }
                        layer.close(index);//取消等待
                    });
                    break;
            }
            ;
        });
    });


</script>
</body>
</html>